#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,fast-math",3)
#define cln cerr<<"Line:   "<<__LINE__<<"    "
#define pct __builtin_popcountll
#define ctz __builtin_ctzll
#define mkp make_pair
#define MST(x) memset(x,0,sizeof(x))
#define all(x) x.begin(),x.end()
using namespace std;
constexpr int N=(1<<21)+100,_g=3,M1=1e9+7,M2=1e9+9,M=998244353;
namespace fast_io{
    char buf[N+10],*p1,*p2,c;
#define gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,N,stdin),p1==p2))?EOF:*p1++
template<typename _Tp>
    void read(_Tp &x){
        int f=0;for(c=gc;c<48;c=gc)f^=c=='-';
        for(x=0;c>47;x=(x<<1)+(x<<3)+(48^c),c=gc);
        if(f)x=-x;
    }
template<typename _Tp,typename..._tps>
    void read(_Tp &x,_tps&...y){read(x),read(y...);}
    char ob[N+100],stk[505];int tp,ot;
    void fls(){fwrite(ob,1,ot,stdout),ot=0;}
    int cntt;
template<typename _Tp>
    static inline void write(_Tp x,char c){
        if(!cntt)atexit(fls),cntt=1;
        while(x>9)stk[++tp]=48^(x%10),x/=10;
        for(ob[ot++]=48^x;tp;ob[ot++]=stk[tp--]);
        ob[ot++]=c;if(ot>N)fls();
    }
}using fast_io::read;
using fast_io::write;
using ll=long long;
#define pli pair<ll,int>
#define pii pair<int,int>
using ul=unsigned long long;
using ld=long double;
mt19937_64 rg(random_device{}());
using ll=long long;
using ul=unsigned long long;
int T,n,m,sz[N],c[N];
ll a[N],b[N],mp[N],sm[N];
ul sr[N];
int MP(ll v){return lower_bound(mp+1,mp+m+1,v)-mp;}
#define ls x<<1
#define rs x<<1|1
void pp(int x){
    sz[x]=sz[ls]+sz[rs];
    sm[x]=sm[ls]+sm[rs];
    sr[x]=sr[ls]+sr[rs]+ul(sm[rs])*sz[ls];
}
void build(int x,int l,int r){
    if(l==r)sr[x]=sm[x]=mp[l]*(sz[x]=c[l]);
    else{
        int md=l+r>>1;
        build(ls,l,md);
        build(rs,md+1,r);pp(x);
    }
}
void cg(int x,int l,int r,int p){
    if(l==r)c[l]^=1,sr[x]=sm[x]=mp[l]*(sz[x]=c[l]);
    else{
        int md=l+r>>1;
        if(p>md)cg(rs,md+1,r,p);
        else cg(ls,l,md,p);pp(x);
    }
}
ul sum;ll mst;int cnt;
void sol1(int x,int l,int r,int k){
    if(l==r){
        if(k)mst+=mp[l];
    }else{
        int md=l+r>>1;
        if(k<sz[ls])sol1(ls,l,md,k);
        else{
            mst+=sm[ls];
            if(k-=sz[ls])sol1(rs,md+1,r,k);
        }
    }
}
ll q1(int k){
    mst=0,sol1(1,1,m,k);
    return mst;
}
ll q2(int k){
    mst=0,sol1(1,1,m,sz[1]-k);
    return sm[1]-mst;
}
void sol2(int x,int l,int r,int k){
    if(l==r){
        if(k){
            sum+=ul(mp[l])*++cnt;
            mst+=mp[l];
        }
    }else{
        int md=l+r>>1;
        if(k<sz[ls])sol2(ls,l,md,k);
        else{
            sum+=sr[ls]+ul(sm[ls])*cnt,cnt+=sz[ls];
            mst+=sm[ls];
            if(k-=sz[ls])sol2(rs,md+1,r,k);
        }
    }
}
ul qL(int r){
    if(!r)return 0;
    sum=mst=cnt=0;
    sol2(1,1,m,r);
    return ul(mst)*(cnt+1)-sum;
}
void sol3(int x,int l,int r,int k){
    if(l==r){
        if(k)sum+=mst+=mp[l];
    }else{
        int md=l+r>>1;
        if(k<sz[rs])sol3(rs,md+1,r,k);
        else{
            sum+=mst*sz[rs]+sr[rs];
            mst+=sm[rs];
            if(k-=sz[rs])sol3(ls,l,md,k);
        }
    }
}
ul qR(int r){
    if(!r)return 0;
    sum=mst=0;
    sol3(1,1,m,r);
    return sum;
}
void sol(){
    if(sz[1]<=1){puts("0");return;}
    int r=sz[1]+1>>1;
    ll v1=q1(r),v2=q2(r-1);
    if(v1>v2){
        printf("%llu\n",sr[1]+sr[1]-ul(sm[1])*(sz[1]+1));
        return;
    }
    if(q1(2)<=q2(1)){
        printf("%lld\n",sm[1]-q1(1)*2);
        return;
    }
    int l=1,md;
    while(l<r){
        md=l+r>>1;
        if(q1(md+1)<=q2(md))r=md;
        else l=md+1;
    }
    --r;
    ul ans=q2(sz[1]-r-1)-q1(r+1);
    ans+=sr[1]+sr[1]-ul(sm[1])*(sz[1]+1);
    ans-=qR(sz[1]-r-1)-qL(sz[1]-r-1);
    ans+=qR(r)-qL(r);
    printf("%llu\n",ans);
}
int main(){
    freopen("kte.in","r",stdin);
    freopen("kte.out","w",stdout);
    ios::sync_with_stdio(false),cin.tie(0);
    int i,j,k,l,r,x,y,z;
    cin>>n;
    for(i=1;i<=n;++i)cin>>a[i],mp[i]=a[i];
    sort(mp+1,mp+n+1),m=unique(mp+1,mp+n+1)-mp-1;
    for(i=1;i<=n;++i){
        cg(1,1,m,MP(a[i]));
        sol();
    }
    return 0;
}